﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace KgUtils.Cryptography
{
    public static partial class CryptoHelper
    {
        public static string ComputeHash(string input)
        {
            //create a byte array from the input string
            var tmpSource = UTF8Encoding.UTF8.GetBytes(input);

            //compute the hash
            var tmpHash = new SHA1CryptoServiceProvider().ComputeHash(tmpSource);
            return ByteArrayToString(tmpHash);
        }

        internal static string ByteArrayToString(byte[] arrInput)
        {
            var sOutput = new StringBuilder(arrInput.Length);
            for (int i = 0; i < arrInput.Length - 1; i++)
            {
                sOutput.Append(arrInput[i].ToString("X2"));
            }
            return sOutput.ToString();
        }
    }
}
